/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package server.boundary;

import server.entities.Transaction;
import server.entities.TransactionType;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

/**
 *
 * @author efim
 */
@Stateless
public class TransactionTypeFacade extends AbstractFacade<TransactionType> {
    @PersistenceContext(unitName = "EFMPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TransactionTypeFacade() {
        super(TransactionType.class);
    }
    
    public List<Transaction> getTransactionTypes(Map<String,String> params)
    {
        CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();        
        Root<TransactionType> transactionType = cq.from(TransactionType.class);
        for (String p : params.keySet()) 
        {
            switch (p) 
            {
                case "id":
                    cq = cq.where(transactionType.get("id").in(params.get(p)));
                    break;
                case "name":
                    cq = cq.where(transactionType.get("name").in(params.get(p)));
                    break;                

            }
        }
        TypedQuery q = getEntityManager().createQuery(cq);
        List list = q.getResultList();
        return list;
        
    }
    
}
